/*** 本文件由CSMIS2.0-ModelCreater(UTF-8)工具辅助生成，版本1.0 ***/

package com.ce.sys.msg.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.StringUtil;
import com.ce.sys.msg.view.SysMsgDefineView;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2013-03-22
* 创建时间：09:51:05
* 功能描述：系统消息定义表 [SYS_T_MSG$DEFINE]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class SysMsgDefineSearchCondition  extends SQLSearchCondition
	implements ISQLMapper
{
	private String msgName;
	private String flag;

	/*
	 * 使用js框架分页时进行排序的必要属性
	 */
	private String order;   //排序方法
	private String sort;  //排序字段


	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}


	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getSearchSql() throws AppException {
		
		StringBuffer sql = new StringBuffer("select t.*,m.vc_name as menuName from SYS_T_MSG$DEFINE t,SYS_T_MENU m where t.VC_DEL$FLAG = 0  and t.vc_action$id = m.vc_id(+) ");
		if(StringUtil.isNotBlank(this.flag))
			sql.append(" and t.N_FLAG = "+ this.getSafeValue(this.flag));
		if(StringUtil.isNotBlank(this.msgName))
			sql.append(" and t.VC_NAME like '%"+this.getSafeValue(this.msgName)+"%'");
		//实现排序的代码
		if(StringUtil.isNotBlank(this.order)){
			if("flagName".equals(this.sort)){
				sql.append("  order by t.N_FLAG "+this.order);
			}	
		}else{
			sql.append("  order by t.N_FLAG desc ");
		}
		return sql.toString();
	}
	
	public Object fromSQLQuery(ResultSet rs, int num) {
		SysMsgDefineView view = new SysMsgDefineView();
		try {

			view.setVcId(rs.getString("VC_ID"));
			view.setVcName(rs.getString("VC_NAME"));
			view.setVcSql(rs.getString("VC_SQL"));
			view.setVcTitle(rs.getString("VC_TITLE"));
			view.setVcUrl(rs.getString("VC_URL"));
			view.setVcRescId(rs.getString("VC_RESC$ID"));
			view.setNflag(rs.getInt("N_FLAG"));
			view.setVcDelFlag(rs.getString("VC_DEL$FLAG"));
			view.setVcActionId(rs.getString("VC_ACTION$ID"));		
			view.setMenuName(rs.getString("menuName"));

		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return view;
	}
	
	public ISQLMapper getSQLMapper() {
		
		return this;
	}


	public String getMsgName() {
		return msgName;
	}

	public void setMsgName(String msgName) {
		this.msgName = msgName;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

}

